/*
 *  This file is part of LifeBudget - Copyright 2010 Clifton Eaton
 *  ------------------------------------------------------------------
 *  LifeBudget is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  LifeBudget is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with LifeBudget.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.lifebudget.app.persistence.dao;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.lifebudget.app.client.mvc.model.CategoryAmount;
import org.lifebudget.app.client.mvc.model.PaycheckCalculator;
import org.lifebudget.app.client.mvc.model.PaycheckCalculator.Interval;

import com.google.appengine.api.datastore.Key;

/**
 * The Class PaycheckCalculatorDAO. Data Access Object in for the persistence
 * layer to handle persisting a {@link PaycheckCalculator}. Annotated for JPA
 * persistence.
 */
@Entity
public class PaycheckCalculatorDAO {

	/** The key. */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key key;
	
	/** The user id. */
	private String userId;

	/**
	 * Gets the user id.
	 *
	 * @return the user id
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * Sets the user id.
	 *
	 * @param userId the new user id
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}

	/** The name. */
	private String name;
	
	/** The estimated amt. */
	private double estimatedAmt;
	
	/** The interval. */
	private String interval;
	
	/** The description. */
	private String description;

	/**
	 * Instantiates a new paycheck calculator dao.
	 *
	 * @param name the name
	 * @param estimatedAmt the estimated amt
	 * @param interval the interval
	 * @param description the description
	 * @param categoryAmounts the category amounts
	 */
	public PaycheckCalculatorDAO(String name, double estimatedAmt, String interval, String description,
			List<Long> categoryAmounts) {
		super();
		this.name = name;
		this.estimatedAmt = estimatedAmt;
		this.interval = interval;
		this.description = description;
	}

	/**
	 * Instantiates a new paycheck calculator dao.
	 *
	 * @param pc the pc
	 */
	public PaycheckCalculatorDAO(PaycheckCalculator pc) {
		super();
		this.name = pc.getName();
		this.estimatedAmt = pc.getEstimatedAmt();
		this.interval = pc.getInterval().toString();
		this.description = pc.getDescription();
	}

	/**
	 * Instantiates a new paycheck calculator dao.
	 */
	public PaycheckCalculatorDAO() {
		super();
	}

	/**
	 * To model object.
	 *
	 * @return the paycheck calculator
	 */
	public PaycheckCalculator toModelObject() {
		PaycheckCalculator pc = new PaycheckCalculator();
		pc.setName(name);
		pc.setEstimatedAmt(estimatedAmt);
		pc.setInterval(Interval.valueOf(interval));
		pc.setDescription(description);
		pc.setId(key.getId());
		return pc;

	}

	/**
	 * Gets the key.
	 *
	 * @return the key
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * Sets the key.
	 *
	 * @param key the new key
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * Gets the name.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the estimated amt.
	 *
	 * @return the estimated amt
	 */
	public double getEstimatedAmt() {
		return estimatedAmt;
	}

	/**
	 * Sets the estimated amt.
	 *
	 * @param estimatedAmt the new estimated amt
	 */
	public void setEstimatedAmt(double estimatedAmt) {
		this.estimatedAmt = estimatedAmt;
	}

	/**
	 * Gets the interval.
	 *
	 * @return the interval
	 */
	public String getInterval() {
		return interval;
	}

	/**
	 * Sets the interval.
	 *
	 * @param interval the new interval
	 */
	public void setInterval(String interval) {
		this.interval = interval;
	}

	/**
	 * Gets the description.
	 *
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the description.
	 *
	 * @param description the new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Sets the fields from model object.
	 *
	 * @param paycheck the new fields from model object
	 */
	public void setFieldsFromModelObject(PaycheckCalculator paycheck) {
		this.name = paycheck.getName();
		this.estimatedAmt = paycheck.getEstimatedAmt();
		this.interval = paycheck.getInterval().toString();
		this.description = paycheck.getDescription();
	}

}
